# -*- coding:utf-8 -*-
from selenium import webdriver
import time,os,xlrd
#从excel中获取输入项
wb=xlrd.open_workbook('F:\\PyWorkSpace\\FilePath\\book1.xls')
sh=wb.sheet_by_name('Sheet1')
row_count=sh.nrows
col_count=sh.ncols
#循环每行数据
for i in range(1,row_count):
    browser = webdriver.Firefox()
    browser.get('http://localhost/iwebshop/index.php?controller=simple&action=reg')
    time.sleep(2)
    # 获取表单对象，赋值
    email = browser.find_element_by_name('email')
    username = browser.find_element_by_name('username')
    password = browser.find_element_by_name('password')
    repassword = browser.find_element_by_name('repassword')
    try:
        email.send_keys(sh.cell_value(i,0))
        username.send_keys(sh.cell_value(i,1))
        password.send_keys(sh.cell_value(i,2))
        repassword.send_keys(sh.cell_value(i,3))
        option=sh.cell_value(i,4)
        submit = browser.find_element_by_class_name('submit_reg').click()
        #获取预期结果，进行比对
        mass='测试未通过 %s'%str(option)
        #出错位置
        aa =browser.find_element_by_name(option).get_attribute('class')
        assert aa=='gray invalid-text',mass
    except AssertionError,msg:
        file=open('F:\\PyWorkSpace\\FilePath\\result.txt', 'wt')
        print str(msg)
        file.write(str(msg))
        file.close()
    finally:
        time.sleep(2)
        browser.quit()

